package cn.itcast.ssh.service.impl;

import java.util.List;

import cn.itcast.ssh.dao.ILeaveBillDao;
import cn.itcast.ssh.domain.Employee;
import cn.itcast.ssh.domain.LeaveBill;
import cn.itcast.ssh.service.ILeaveBillService;
import cn.itcast.ssh.utils.SessionContext;

public class LeaveBillServiceImpl implements ILeaveBillService {

	private ILeaveBillDao leaveBillDao;

	public void setLeaveBillDao(ILeaveBillDao leaveBillDao) {
		this.leaveBillDao = leaveBillDao;
	}

	@Override
	public List<LeaveBill> findLeaveBillList() {
		List<LeaveBill> list = leaveBillDao.findLeaveBillList();
		return list;
	}
	
	@Override
	public void saveLeaveBill(LeaveBill leaveBill) {
		//判断修改还是更新
		Long id = leaveBill.getId();
		if(id == null) {
			//1.从session中获取当前用户
			Employee employee = SessionContext.get();
			leaveBill.setUser(employee);
			leaveBillDao.saveLeaveBill(leaveBill);
		}else {
			//更新,执行保存操作
			leaveBillDao.updateLeaveBill(leaveBill);
		}
	}

	@Override
	public LeaveBill findLeaveBillById(Long id) {
		return leaveBillDao.findLeaveBillById(id);
	}

	@Override
	public void deleteLeaveBillById(Long id) {
		leaveBillDao.deleteLeaveBillById(id);		
	}
}
